<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tìm nâng cao</title>
</head>

<body>
<?php  include_once($_SERVER['DOCUMENT_ROOT']."/mba/ketnoiCSDL.php"); 
	
?>

<form name="timnangcao" method="POST" >
<div align="center"><strong>T&igrave;m ki&#7871;m n&acirc;ng cao</strong></div>
<p>&nbsp;</p>
<p>C&ocirc;ng su&#7845;t: 
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="txtcongsuat" type="text" size="50" /> 
  (KV)
</p>
<p align="left">&#272;&#417;n v&#7883; &#273;i&#7879;n l&#7921;c:
  &nbsp;&nbsp;&nbsp;<select name="cbodonvi">
	<option value=""></option>
	<?php
		$sql="select * from don_vi order by TEN_DON_VI";		
		$result=mysql_query($sql,$link);
		while ($rows = mysql_fetch_array($result)){
		$r1=$rows["MA_DON_VI"];
		$r2=$rows["TEN_DON_VI"];
		echo "<option value='".$r1."'>".$r2."</option>";
		}
	?>  	

  </select>	
</p>
<p align="left">T&ecirc;n tr&#7841;m:
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <select name="cbotram" id="cbotram">
  <option value=""></option>
  <?php
		$sql="select * from tram order by TEN_TRAM";		
		$result=mysql_query($sql,$link);
		while ($rows = mysql_fetch_array($result)){
		$r1=$rows["MA_TRAM"];
		$r2=$rows["TEN_TRAM"];
		echo "<option value='".$r1."'>".$r2."</option>";
		}
	?>  	

  </select>
</p>
<p align="left">T&igrave;nh tr&#7841;ng: 
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="cbotinhtrang" id="cbotinhtrang">
  <option value=""></option>
  <?php
		$sql="select * from tinh_trang_may order by TEN_TINH_TRANG_MAY";		
		$result=mysql_query($sql,$link);
		while ($rows = mysql_fetch_array($result)){
		$r1=$rows["TEN_TINH_TRANG_MAY"];
		echo "<option value='".$r1."'>".$r1."</option>";
		
		}
	?>  	
  </select>
</p>
<p align="center">
  <input type="submit" name="btnSearchnangcao" value="Tìm" />
</p>

<?php
 if ($_SERVER['REQUEST_METHOD'] == 'POST'){
	if(isset($_POST["btnSearchnangcao"])){
		$congsuat=trim($_POST['txtcongsuat']);
		if($_POST['txtcongsuat']=="") {$congsuat="%";}
		$from="may_bien_ap a";
		$where="";
		if($_POST['cbodonvi']=="" && $_POST['cbotram']=="" && $_POST['cbotinhtrang']==""){
			$where.="CONG_SUAT like '".$congsuat."'";
		}
		else if($_POST['cbodonvi']=="" && $_POST['cbotram']==""){
			$from.=",tinh_trang_may b";
			$where.="a.SO_N0=b.SO_N0 and CONG_SUAT like '".$congsuat."' and b.TEN_TINH_TRANG_MAY='".$_POST['cbotinhtrang']."'";
		}
		else if($_POST['cbodonvi']=="" && $_POST['cbotinhtrang']==""){
			$from.=",mba_tram b";
			$where.="a.SO_N0=b.SO_N0 and CONG_SUAT like '".$congsuat."'and b.MA_TRAM like '".$_POST['cbotram']."'";
		}
		else if($_POST['cbotram']=="" && $_POST['cbotinhtrang']==""){
			$from.=",chi_tiet_so_huu b";
			$where.="a.SO_N0=b.SO_N0 and CONG_SUAT like '".$congsuat."'and b.MA_DON_VI like '".$_POST['cbodonvi']."'";
		}
		else if($_POST['cbodonvi']==""){
			$from.=",mba_tram b, tinh_trang_may c";
			$where.="a.SO_N0=b.SO_N0 and a.SO_N0=c.SO_N0 and CONG_SUAT like '".$congsuat."' and b.MA_TRAM like '".$_POST['cbotram']."' and c.TEN_TINH_TRANG_MAY='".$_POST['cbotinhtrang']."'";			
		}
		else if($_POST['cbotram']==""){
			$from.=",chi_tiet_so_huu b, tinh_trang_may c";
			$where.="a.SO_N0=b.SO_N0 and a.SO_N0=c.SO_N0 and CONG_SUAT like '".$congsuat."' and b.MA_DON_VI like '".$_POST['cbodonvi']."' and c.TEN_TINH_TRANG_MAY ='".$_POST['cbotinhtrang']."'";
		}
		else if($_POST['cbotinhtrang']==""){
			$from.=",chi_tiet_so_huu b, mba_tram c";
			$where.="a.SO_N0=b.SO_N0 and a.SO_N0=c.SO_N0 and CONG_SUAT like '".$congsuat."' and b.MA_DON_VI like '".$_POST['cbodonvi']."' and c.MA_TRAM= '".$_POST['cbotram']."'";
		}
		else{
			$from.=",chi_tiet_so_huu b, mba_tram c, tinh_trang_may d";
			$where.="a.SO_N0=b.SO_N0 and a.SO_N0=c.SO_N0 and a.SO_N0 = d.SO_N0 and CONG_SUAT like '".$congsuat."' and b.MA_DON_VI like '".$_POST['cbodonvi']."' and c.MA_TRAM like '".$_POST['cbotram']."' and d.TEN_TINH_TRANG_MAY='".$_POST['cbotinhtrang']."'";
		}
		
		$sql="select * from ".$from." where ".$where;
	
		$result=mysql_query($sql,$link);
		
		if(mysql_num_rows($result)!=0)
  			{
			session_start();					
		$_SESSION["congsuat"]=$congsuat;
		$_SESSION["donvi"]=$_POST['cbodonvi'];
		$_SESSION["tram"]=$_POST['cbotram'];
		$_SESSION["tinhtrang"]=$_POST['cbotinhtrang'];		
			
			echo "<script language='javascript'>window.open('kqtimnangcao.php')</script>";
			}
	
		else {	
			echo "<script language='javascript'>window.open('kocokq.php')</script>";
			//echo "<script type='text/javascript'> alert('Không tìm thấy kết quả'); </script>";
		}
	}
}
?>

</body>
</html>
